var getHomework = function(){
    var result=$.ajax({
        url:"/student/homework/all",
        type:"GET",
        async:false
    });
    $("#main-content").html(result.responseText);
}

function submitHomework(){
    var formData = new FormData();
    var name = $("#homeworkFile").val();
    var homeworkId = $("#fileHomeworkId").val();
    formData.append("file",$("#homeworkFile")[0].files[0]);
    formData.append("name",name);
    formData.append("homeworkId",homeworkId);
    $.ajax({
        url : '/student/homework/submit',
        type : 'POST',
        async : false,
        data : formData,
        // 告诉jQuery不要去处理发送的数据
        processData : false,
        // 告诉jQuery不要去设置Content-Type请求头
        contentType : false,
        success : function(responseStr) {
            if(responseStr=="successful"){
                alert("导入成功");
            }else{
                alert(responseStr);
            }
        }
    });
    $('#homeworkUpload').modal('hide');
    getHomework();
}

function updateHomeworkModel(homeworkId){
    $("#fileHomeworkId").val(homeworkId)
}

function readDocumentByHomework(homeworkId){
    $.ajax({
        url: "/student/homework/download",
        type:"GET",
        async : false,
        data : {
            homeworkId : homeworkId
        },
        success : function(responseStr) {
            console.log(responseStr.docId)
            var option = {
                docId: responseStr.docId,
                token: 'TOKEN',
                host: 'BCEDOC',
                serverHost: 'http://doc.bj.baidubce.com',
                width: 600, //文档容器宽度
                zoom: false,              //是否显示放大缩小按钮
                zoomStepWidth:200,
                ready: function (handler) {  // 设置字体大小和颜色, 背景颜色（可设置白天黑夜模式）
                    handler.setFontSize(1);
                    handler.setBackgroundColor('#000');
                    handler.setFontColor('#fff');
                },
                flip: function (data) {    // 翻页时回调函数, 可供客户进行统计等
                    console.log(data.pn);
                },
                fontSize:'big',
                toolbarConf: {
                        page: true, //上下翻页箭头图标
                        pagenum: true, //几分之几页
                        full: false, //是否显示全屏图标,点击后全屏
                        copy: true, //是否可以复制文档内容
                        position: 'center',// 设置 toolbar中翻页和放大图标的位置(值有left/center)
                } //文档顶部工具条配置对象,必选
            };
            new Document('docContent', option);
        }
    });
}